<!-- 头部 -->
@layout("/layout/header.html"){ 
@}
<div class="am-cf admin-main ">
<!-- 左侧菜单-->
@layout("/layout/sidebar.html",{}){ 
@}
	<div class="admin-content">
		<div class="am-cf am-padding">
			<div class="am-fl am-cf">
				<strong class="am-text-primary am-text-lg">首页</strong> / <small>项目管理</small>
			</div>
		</div>

		<div class="am-g">
			<div class="am-u-sm-12 am-u-md-6">
				<div class="am-btn-toolbar">
					<div class="am-btn-group am-btn-group-xs">
						<a type="button" class="am-btn am-btn-primary" action="add"><span class="am-icon-plus"></span> 新增</a>
						<!--  <a type="button" class="am-btn am-btn-success"  action="update"><span class="am-icon-plus"></span> 修改</a> -->
						<a type="button" class="am-btn am-btn-danger" action="deleteAll"><span class="am-icon-trash-o"></span> 删除</a>
					</div>
				</div>
			</div>

			<div class="am-u-sm-12 am-u-md-3">
				<div class="am-input-group am-input-group-sm">
					<input type="text" class="am-form-field"> <span
						class="am-input-group-btn">
						<button class="am-btn am-btn-default" type="button">搜索</button>
					</span>
				</div>
			</div>
		</div>

		<div class="am-g">
			<div class="am-u-sm-12">
				<form class="am-form" id="queryForm" action="${ctxPath}/project"
					method="post">
					<table class="am-table am-table-striped am-table-hover table-main">
						<thead>
							<tr>
								<th class="table-check"><input type="checkbox" /></th>
								<th>项目名称</th>
								<th>输出路径</th>
								<th>作者</th>
								<th>联系方式</th>
								<th>描述</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>

							@for(item in page.list){
							<tr>
								<td><input type="checkbox" /></td>
								<td>${ item.name!}</td>
								<td>${ item.outPath!}</td>
								<td>${ item.author!}</td>
								<td>${ item.contact!}</td>
								<td>${ item.description!}</td>
								<td>
									<div class="am-btn-toolbar">
										<div class="am-btn-group am-btn-group-xs">
											<a class="am-btn am-btn-secondary am-round" key="${ item.id!}" action="update"><span class="am-icon-edit"></span> 编辑</a> 
											<a class="am-btn am-btn-danger am-round" key="${ item.id!}" action="delete"><span class="am-icon-trash"></span> 删除</a>
										</div>
									</div>
								</td>
							</tr>
							@}

						</tbody>
					</table>
					@include("/layout/_pagination.html",{page:page}){}
				</form>
			</div>

		</div>
	</div>

	<!-- content end -->

	<div class="am-popup" id="my-popup">
		<div class="am-popup-inner">
			<div class="am-popup-hd">
				<h4 class="am-popup-title">新增</h4>
				<span data-am-modal-close class="am-close">&times;</span>
			</div>
			<div class="am-popup-bd">
				<div>
					<form action="" class="am-form" id="doc-vld-msg">
						<div class="am-form-group">
							<label for="doc-select-1-1">项目名称</label> 
							<input type="text" id="doc-select-1-1" name="name" placeholder="输入项目名称" required />
						</div>

						<div class="am-form-group">
							<label for="doc-vld-outPath-2-1">输出文件路径：</label> 
							<input type="text" id="doc-vld-outPath-2-1" name="outPath" placeholder="输入输出文件路径" required />
						</div>

						<div class="am-form-group">
							<label for="doc-vld-author-2-1">作者：</label> 
							<input type="text" id="doc-vld-author-2-1" name="author" placeholder="输入作者"  />
						</div>

						<div class="am-form-group">
							<label for="doc-vld-contact-2-1">联系方式：</label> 
							<input type="text" id="doc-vld-contact-2-1" name="contact" placeholder="输入联系方式"  />
						</div>

						<div class="am-form-group">
							<label for="doc-vld-description-2-1">描述：</label> 
      						<textarea id="doc-vld-description-2-1"  name="description" maxlength="100"></textarea>
						</div>

						<div class="am-form-group">
							<div class="am-u-sm-5 am-u-sm-push-5">
								<input type="hidden" name="id" id="id" /> 
								<a class="am-btn am-btn-primary save">提交</a> 
								<a class="am-btn am-btn-danger quite">取消</a>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>

	<!-- model end -->

</div>
<!-- 底部 -->
@layout("/layout/footer.html"){ 
@}
<script>
$(function (){
	var $modal = $('#my-popup'),$form = $("#doc-vld-msg"),action="",$table = $('.table');
	
	//表单验证
 	$('#doc-vld-msg').validator({
	    onValid: function(validity) {
	      $(validity.field).closest('.am-form-group').find('.am-alert').hide();
	    },
	    onInValid: function(validity) {
	      var $field = $(validity.field);
	      var $group = $field.closest('.am-form-group');
	      var $alert = $group.find('.am-alert');
	      // 使用自定义的提示信息 或 插件内置的提示信息
	      var msg = $field.data('validationMessage') || this.getValidationMessage(validity);
	      if (!$alert.length) {
	          $alert = $('<div class="am-alert am-alert-danger"></div>').hide().
	          appendTo($group);
	      }
	      $alert.html(msg).show();
	    }
	});
 	
 	//按钮点击
 	 $('.am-btn-group-xs a').click(function() {
		var ac = $(this).attr('action');
		var key = $(this).attr('key');
		action = ac;
		
		if ('add' == ac) {
			$modal.modal('open');
		} else if ('update' == ac) {
			$modal.modal('open');
			$.post("${ctxPath}/project/view", {id: key}, function(rs) {
				if (rs) {
					Utils.setForm($form, rs);
				} else {
					alert('请选择一项！');
				}
			});
			
		} else if ('delete' == ac) {
			var param = {id : key};
 			save(action,param);
		} else if ('deleteAll' == ac) {
			
		}
		
		
	}); 
 	
 	//关闭窗口
 	$('.quite').click(function() {
 		$modal.modal('close');
 	});
 	
	//保存
 	$(".save").click(function(){
 		if (action) {
 			var id = $("#id").val();
 			if(!id){
 				$("#id").val("-1");
 			}
 			var param = $form.serialize();
 			save(action,param);
		}
 	});
	
	function save(action,parame){
		$.post("${ctxPath}/project/save/"+ action, parame, function(rs) {
			if (rs && 200 == rs.status) {
				location.reload();
			} else {
				alert(rs.message);
			}
		});
	}
 	
})
</script>

